package com.harmontronics.hanma.paas.paas.controller;

import com.harmontronics.hanma.paas.paas.domain.iam.entity.UserGroupReport;
import com.harmontronics.hanma.paas.paas.domain.iam.entity.UserGroupReportCreate;

import java.util.List;

import cn.hutool.core.bean.BeanUtil;
import com.harmontronics.hanma.paas.paas.common.ResponseEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import com.harmontronics.hanma.paas.paas.service.HmUserGroupReportAppService;
import com.harmontronics.hanma.paas.paas.dto.iam.input.HmUserGroupReportCreateInput;


/**
 * 用户组-报表
 *
 * @author paas-generator
 * @email paas-generator@harmontronics.com
 * @date 2021-04-27 16:31:45
 */
@RestController
@RequestMapping("/api/hmusergroupreport")
@Api(tags = {"用户组-报表"})
public class HmUserGroupReportController {
    @Autowired
    private HmUserGroupReportAppService hmUserGroupReportappService;



    @GetMapping("/list")
    @ApiOperation(value = "可见范围-展现使用列表")
    public ResponseEntity<List> list(@RequestParam Long groupId) {
        return ResponseEntity.ok(hmUserGroupReportappService.selectUserGroupReportWithGroupId(groupId));
    }


    @PostMapping
    @ApiOperation(value = "添加用户组报表")
    public ResponseEntity create(@RequestBody HmUserGroupReportCreateInput userGroupOrgCreate) {
        UserGroupReportCreate reportCreate = BeanUtil.toBean(userGroupOrgCreate,
                UserGroupReportCreate.class);
        hmUserGroupReportappService.create(reportCreate);
        return ResponseEntity.ok();
    }

    @DeleteMapping
    @ApiOperation(value = "删除用户组报表")
    public ResponseEntity delete(@RequestParam Long id) {
        // 删除子节点对应的三个范围
        hmUserGroupReportappService.removeChildGroup(id);
        hmUserGroupReportappService.removeById(id);
        return ResponseEntity.ok();
    }

    @GetMapping("/select-list")
    @ApiOperation("可见范围-已选择列表")
    public ResponseEntity<List<UserGroupReport>> selectList(@RequestParam Long groupId){
        List<UserGroupReport> reportList = hmUserGroupReportappService.selectList(groupId);
        return ResponseEntity.ok(reportList);
    }

    @GetMapping("/user-report")
    @ApiOperation("当前用户可见报表列表")
    public ResponseEntity<List<UserGroupReport>> selectByUser(){
        List<UserGroupReport> reportList = hmUserGroupReportappService.selectByUser();
        return ResponseEntity.ok(reportList);
    }
}
